<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue-2.6.12.js"></script>
    <script src="./js/vue-router-3.4.3.js"></script>
</head>

<body>
    <div id="app">
        <div>
            <router-link to="/user">用户界面</router-link>
            <router-link to="/manager">管理员界面</router-link>
        </div>
        <div>
            <router-view></router-view>
        </div>
    </div>
    <script>
        let myA = {
            template: `
            <div>用户</div>
            `
        };
        let myB = {
            template: `
            <div>
                <div>
                    <router-link to="/managerChild1">子组件1</router-link>
                    <router-link to="/managerChild2">子组件2</router-link>
                </div>
                <div>
                    <router-view></router-view>
                </div>
            </div>
            `
        };
        let child1 = {
            template: `
            <div>子组件1</div>
            `
        };
        let child2 = {
            template: `
            <div>子组件2</div>
            `
        };
        let routes = [
            {
                path: '/user',
                component: myA
            },
            {
                path: '/manager',
                component: myB,
                redirect:'/managerChild1',
                // 二级路由
                children: [
                    {
                        path: '/managerChild1',
                        component: child1
                    },
                    {
                        path: '/managerChild2',
                        component: child2
                    }
                ]
            }
        ];
        let router = new VueRouter({
            routes: routes
        });
        new Vue({
            el: "#app",
            router,
            components: {
                'my-a': myA,
                'my-b': myB
            },
            data: {},
            methods: {

            },
        })
    </script>
</body>

</html>